package com.shioirikukuri.service.impl;

import com.shioirikukuri.entity.Order;
import com.shioirikukuri.mapper.OrderMapper;
import com.shioirikukuri.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements IOrderService {

	@Autowired
	private OrderMapper orderMapper;

	@Override
	public void createOrder(Order order) {
		orderMapper.insertOrder(order);
	}

	@Override
	public Order getOrderById(String orderId) {
		return orderMapper.selectById(orderId);
	}

	@Override
	public void updateOrderStatus(String orderId, String status) {
		orderMapper.updateStatusById(orderId, status);
	}

	@Override
	public void handlePaymentSuccess(String orderId, String paymentTime) {
		orderMapper.updatePaymentTimeAndStatus(orderId, paymentTime, Order.STATUS_PAID);
	}

	@Override
	public void handleRefundSuccess(String orderId, String refundedTime) {
		orderMapper.updateRefundedTimeAndStatus(orderId, refundedTime, Order.STATUS_REFUNDED);
	}
}